<?php
// +----------------------------------------------------------------------
// | xiongrui [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.xiongrui.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.xiongrui.cn>
// +----------------------------------------------------------------------

namespace app\admin\controller;
use app\admin\validate\DeliveryArayacakValidate;
use app\common\controller\Admin;

class Delivery extends Admin {
  protected $DeliveryArea;
  protected $DeliveryTime;
  protected $DeliveryPerson;
  protected $DeliveryArayacak;
  public function _initialize() {
		parent::_initialize();
    $this->DeliveryArea = model('DeliveryArea');
    $this->DeliveryTime = model('DeliveryTime');
    $this->DeliveryPerson = model('DeliveryPerson');
    $this->DeliveryArayacak = model('DeliveryArayacak');
	}

  public function area() {
		$this->setMeta('区域设置');
		return $this->fetch();
	}

  public function addArea(){
    if (IS_POST) {
      	$result = $this->DeliveryArea->change();
      if($result){
        $this->success('添加成功！');
      }else{
        $this->error('添加失败！');
      }
    }
  }

  public function delArea() {
		$id = $this->getArrayParam('id');
		if (empty($id)) {
			return $this->error("非法操作！");
		}
		$result = $this->DeliveryArea->where(array('id' => array('IN', $id)))->delete();
		if ($result) {
			return $this->success("删除成功！");
		} else {
			return $this->error("删除失败！");
		}
	}

  public function time() {
    $list = $this->DeliveryTime->where($map)->order('id desc')->select();
		$this->assign('list', $list);
		$this->setMeta('配送时间');
		return $this->fetch();
	}

  public function addTime(){
    if (IS_POST) {
      	$result = $this->DeliveryTime->change();
      if($result){
        $this->success('添加成功！');
      }else{
        $this->error('添加失败！');
      }
    }
  }

  public function delTime() {
		$id = $this->getArrayParam('id');
		if (empty($id)) {
			return $this->error("非法操作！");
		}
		$result = $this->DeliveryTime->where(array('id' => array('IN', $id)))->delete();
		if ($result) {
			return $this->success("删除成功！");
		} else {
			return $this->error("删除失败！");
		}
	}

  public function person() {
    $list = $this->DeliveryPerson->where($map)->order('id desc')->select();
		$this->assign('list', $list);
		$this->setMeta('配送师傅');
		return $this->fetch();
	}

  public function addPerson(){
    if (IS_POST) {
      	$result = $this->DeliveryPerson->change();
      if($result){
        $this->success('添加成功！');
      }else{
        $this->error('添加失败！');
      }
    }
  }

  public function delPerson() {
		$id = $this->getArrayParam('id');
		if (empty($id)) {
			return $this->error("非法操作！");
		}
		$result = $this->DeliveryPerson->where(array('id' => array('IN', $id)))->delete();
		if ($result) {
			return $this->success("删除成功！");
		} else {
			return $this->error("删除失败！");
		}
	}

  public function arayacak() {
    $list = $this->DeliveryArayacak->order('id desc')->select();
      Cookie('__forward__',$_SERVER['REQUEST_URI']);
		$this->assign('list', $list);
		$this->setMeta('自提点设置');
		return $this->fetch();
	}

  public function addArayacak($id = ''){
    if (IS_POST) {
		(new DeliveryArayacakValidate())->goVerify();
      	$result = $this->DeliveryArayacak->change();
      if($result){
        $this->success('操作成功！', url('admin/delivery/arayacak'));
      }else{
        $this->error('添加失败！');
      }
    }else{
        $info = '';
    	if($id){
            $info = $this->DeliveryArayacak->find($id);
		}

        $data = array(
            'info'    => $info,
            'keyList' => $this->DeliveryArayacak->addfield(),
        );

        $this->assign($data);
        $this->setMeta("自提点设置");
        return $this->fetch('public/edit');
	}
  }

  public function delArayacak() {
		$id = $this->getArrayParam('id');
		if (empty($id)) {
			return $this->error("非法操作！");
		}
		$result = $this->DeliveryArayacak->where(array('id' => array('IN', $id)))->delete();
		if ($result) {
			return $this->success("删除成功！");
		} else {
			return $this->error("删除失败！");
		}
	}



}

 ?>
